import pyautogui
import time
import os

# 设置保存截图的文件夹
save_folder = "screenshots"
if not os.path.exists(save_folder):
    os.makedirs(save_folder)

# 设置截屏次数和间隔时间
num_screenshots = 10
interval = 0.05  # 0.1秒截屏一次

for i in range(num_screenshots):
    # 截屏
    screenshot = pyautogui.screenshot()

    # 生成文件名
    timestamp = time.strftime("%Y%m%d_%H%M%S")
    filename = os.path.join(save_folder, f"screenshot_{timestamp}_{i}.png")

    # 保存截图
    screenshot.save(filename)

    # 等待指定的时间间隔
    time.sleep(interval)

print(f"{num_screenshots}张截图已保存到'{save_folder}'文件夹中。")